<?php
/*------------------------------------------------------------------------
# com_k2store - K2 Store v 2.6
# ------------------------------------------------------------------------
# author    Ramesh Elamathi - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2012 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://k2store.org
# Technical Support:  Forum - http://k2store.org/forum/index.html
-------------------------------------------------------------------------*/



$item = @$this->item;
$formName = 'k2storeadminForm_'.$item->product_id;
require_once (JPATH_SITE.'/components/com_k2store/helpers/cart.php');
require_once (JPATH_ADMINISTRATOR.'/components/com_k2store/library/select.php');
$action = JRoute::_('index.php?option=com_k2store&view=mycart');
?>
<div class="k2store">
<div class="span12">
<?php if(count(JModuleHelper::getModules('k2store-addtocart-top')) > 0 ): ?> 
	<div class="k2store_modules">
		<?php echo K2StoreHelperModules::loadposition('k2store-addtocart-top'); ?>
	</div>
<?php endif; ?>
<form action="<?php echo $action; ?>" method="post" class="k2storeCartForm" id="<?php echo $formName; ?>" name="<?php echo $formName; ?>" enctype="multipart/form-data">
	
	<?php if($this->params->get('show_price_field', 1)):?>
	<!--base price-->
    	<span id="product_price_<?php echo $item->product_id; ?>" class="product_price">
    		<?php  echo K2StoreHelperCart::dispayPriceWithTax($item->price, $item->tax, $this->params->get('price_display_options', 1)); ?>
    	</span>

   <?php endif; ?> 
   <?php if($this->params->get('show_qty_field', 1)):?>
     	<div id='product_quantity_input_<?php echo $item->product_id; ?>' class="product_quantity_input">
			<span class="title"><?php echo JText::_( "K2STORE_ADDTOCART_QUANTITY" ); ?>:</span>
			<input type="text" name="product_qty" value="<?php echo $item->product_quantity; ?>" size="5" />
      	</div>
		<?php else:?>
		<input type="hidden" name="product_qty" value="<?php echo $item->product_quantity; ?>" size="5" />	
  <?php endif; ?>
  <!--attribute options-->
			<div id='product_attributeoptions_<?php echo $item->product_id; ?>' class="product_attributeoptions">
			    <?php
			    $default = K2StoreHelperCart::getDefaultAttributeOptions($this->attributes);
			    
			    foreach ($this->attributes as $attribute)
			    {
			    	$attribs = array('class' => 'inputbox', 'size' => '1');
			        ?>
			        <div class="pao" id='productattributeoption_<?php echo $attribute->productattribute_id; ?>'>
			        <?php
			        echo "<span class='attribute_title'>".$attribute->productattribute_name."&nbsp;";
			        $required = K2StoreSelect::getAttributeRequired($attribute->productattribute_id);

			        if($required) {
			        	$attribs = array('class' => 'inputbox required', 'size' => '1');
			        	echo '*';
			        } else {
			        	$attribs = array('class' => 'inputbox', 'size' => '1');
			        }
					echo "</span>";
					
			        $key = 'attribute_'.$attribute->productattribute_id;
			        $selected = (!empty($values[$key])) ? $values[$key] : $default[$attribute->productattribute_id];
			
			         // Selected attribute options (for child attributes)
					$selected_opts = (!empty($this->selected_opts)) ? json_decode($this->selected_opts) : 0;
			
					if(!count($selected_opts))
					{
						$selected_opts = 0;
					}
			        //now choose the format: select or radio
			        $format = K2StoreSelect::getAttributeDisplayFormat($attribute->productattribute_id);
			        if($format == 'radio') {
			        	//echo K2StoreSelect::productattributeoptions( $attribute->productattribute_id, $selected, $key, $attribs, null, $selected_opts  );
			        	echo K2StoreSelect::radio_productattributeoptions( $attribute->productattribute_id, $selected, $key, $attribs, $idtag = null, $required, $selected_opts  );
			        } else {
			        	echo K2StoreSelect::productattributeoptions( $attribute->productattribute_id, $selected, $key, $attribs,  $idtag = null, $required, $selected_opts  );
			        }

			        
			        ?>
			
			        </div>
			        <?php
			    }
			    ?>

    		</div> <!-- end of attribute options -->
	

     <!-- Add to cart button -->
		<div id='add_to_cart_<?php echo $item->product_id; ?>' class="k2store_add_to_cart" style="display: block;">
	        <input type="hidden" name="product_id" value="<?php echo $item->product_id; ?>" />
	        <input type="hidden" id="task" name="task" value="" />
	        <?php echo JHTML::_( 'form.token' ); ?>
	        <input type="hidden" name="return" value="<?php echo base64_encode( JUri::getInstance()->toString() ); ?>" />
	        <input value="<?php echo JText::_('K2STORE_ADD_TO_CART'); ?>" type="submit" class="k2store_cart_button btn btn-primary" />
	    </div>

</form>

	<?php if(count(JModuleHelper::getModules('k2store-addtocart-bottom')) > 0 ): ?> 
	<div class="k2store_modules">
		<?php echo K2StoreHelperModules::loadposition('k2store-addtocart-bottom'); ?>
	</div>
	<?php endif; ?>
	
</div>
</div>